<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>挂靠公司列表</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <!-- 是否显示提交按钮 -->
    <sys:funcAuth resCd="LinkSubmit">
        <span id="isShowCmtBtn"/>
    </sys:funcAuth>
    <!-- 是否显示审核按钮 -->
    <sys:funcAuth resCd="LinkCheck">
        <span id="isShowAudBtn"/>
    </sys:funcAuth>
    <sys:funcAuth resCd="LinkCrAmt">
        <span id="isShowLinkCrAmtBtn"/>
    </sys:funcAuth>
    <!--是否显示变更按钮-->
    <sys:funcAuth resCd="LnkModify">
        <span id="isShowLnkModifyBtn" />
    </sys:funcAuth>
    <sys:funcAuth resCd="blacklist">
        <span id="blackList" />
    </sys:funcAuth>
    <!-- 是否显示操作日志 -->
    <sys:funcAuth resCd="LnkRiskLog">
        <span id="isLnkRiskLog" />
    </sys:funcAuth>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="挂靠公司列表" lselected="true">
            <div class="searchArea">
                <form id="searchBar">
                    <div class="fieldset1 clearFix">
                        <div class="fieldBox">
                            <div class="label">挂靠公司名称</div>
                            <div class="field">
                                <input name="lnkCompNm" id="lnkCompNm" type="text"
                                       class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">审核状态</div>
                            <div class="field">
                                <select name="audStsCd" id="audStsCd" data-value="">
                                    <option value="  " selected="selected">--请选择--</option>
                                    <c:forEach items="${keyValueList}" var="item">
                                        <c:if test="${item.key != 5 && item.key != 6}">
                                            <option value="${item.key}">${item.value }</option>
                                        </c:if>
                                    </c:forEach>
                                    <option value="99">变更审核中</option>
                                </select>
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">姓名</div>
                            <div class="field">
                                <input name="rlNm" id="rlNm" type="text"
                                       class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">证件号</div>
                            <div class="field">
                                <input name="certNo" id="certNo" type="text"
                                       class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">手机号</div>
                            <div class="field">
                                <input name="rlTel" id="rlTel" type="text"
                                       class="ui-textbox" value="">
                            </div>
                        </div>
                        <div  class="fieldBox">
                            <div class="label">渠道担保业务</div>
                            <div class = "field">
                                <select name="guarCd" id="guarCd" data-value=" ">
                                    <option value=" " seleted>请选择</option>
                                    <option value="8">渠道保证金担保业务</option>
                                    <option value="9">代偿担保业务</option>
                                </select>
                            </div>
                        </div>
                        <div  class="fieldBox">
                            <div class="label">代偿担保合同生效状态</div>
                            <div class = "field">
                                <select name="compEffectIsValid" id="compEffectIsValid" data-value=" ">
                                    <option value=" " seleted>请选择</option>
                                    <option value="0">无效</option>
                                    <option value="1">有效</option>
                                </select>
                            </div>
                        </div>
                        <div class="clearFix"></div>
                        <div class="btnsBox">
                            <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                            <span id="clear" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
                            <span id="addBtn" onclick="addBefore();" class="sq-button sq-button-round">新增</span>
                            <%--<span id="flowStartBtn" onclick="flowStartBtn();"
                                  class="sq-button sq-button-round">发起流程</span>--%>
                        </div>
                    </div>
                </form>

            </div>
       <div class="sqPanel" style="margin-bottom: 0;">
	    <div class="sqPanel_head" style="float:right;color: red">
	        <table class="table_full">
	            <tr>
	                <td>
	                	<font color="blue"><i class="ico_flasher_blue"></i>有效期前15天</font>
						<font color="red"><i class="ico_flasher"></i>有效期已超期</font>
	                </td>
	            </tr>
	        </table>
	    </div>
	    <div class="sqPanel_body">
			<div id="ligergrid1" class="sq-grid"></div>
		</div>
	</div>
           <!--  <div id="ligergrid1" class="sq-grid"></div> -->
        </div>
        <div tabid="tabB" title="流程跟踪" id="tabBId">
            <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
        </div>
        <!-- <div tabid="tabC" title="变更记录" id="tabCId">
            <iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
        </div> -->
    </div>
</div>

<!--新增挂靠公司时，展示新增页面-->
<div id="div_lnk_comp" style="display: none">
    <form id="div_lnk_comp_form">
        <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
            <div class="fieldBox col_50">
                <div class="label">公司名称</div>
                <div class="field">
                    <input name="lnkCompNmBk" id="lnkCompNmBk" type="text"
                           class="ui-textbox" value="" validate="{required:true}"> <span
                        class="requiredSymbol">*</span>
                </div>
            </div>
            <!-- <div class="fieldBox col_50">
                <div class="label">组织机构代码</div>
                <div class="field">
                    <input name="orgCode" id="orgCode" type="text" class="ui-textbox"
                           value="" validate="{required:true}"> <span
                        class="requiredSymbol">*</span>
                </div>
            </div> -->
            <!-- <div class="fieldBox col_50">
                <div class="label">营业执照注册号</div>
                <div class="field">
                    <input name="bizLicNo" id="bizLicNo" type="text" isShow="isother"
                           class="ui-textbox" value="" validate="{required:true}"> <span
                        class="requiredSymbol" isShow="isother">*</span>
                </div>
            </div> -->
            <!-- <div class="fieldBox col_50">
                <div class="label">税务登记号</div>
                <div class="field">
                    <input name="taxRegNo" id="taxRegNo" type="text"
                           class="ui-textbox" value="" validate="{required:true}"> <span
                        class="requiredSymbol">*</span>
                </div>
            </div> -->
        </div>
	    <div class="btnsBox">
			<span id="hintSpan" style="color:#ff0000;display:none">系统未在工商网中查到此公司，请核对公司名称是否正确</span>
		</div>

		<div class="btnsBox">
	        <span id="okBtn1" class="sq-button sq-button-round">确定</span>
	        <span id="okBtn2" style="display:none;" class="sq-button sq-button-round">继续编辑</span>
	        <span id="cancelBtn" class="sq-button sq-button-round">取消</span>
	    </div>
    </form>

</div>

<!-- 操作原因 -->
<form id="reasonFromSet" style="display:none;">
	<div class="field">
		<textarea name="reason" id="reason" class="ui-textarea l-textarea" style="width:360px;height: 150px;" validate="{required:true}" ></textarea>
	</div>
</form>

<script type="text/javascript">
    var grid = null;
    var buOrgCd = '${buOrgCd}';
    var pageInApp = {}; // to 下一级子窗口 接口
    var pageInTab = null;
    var clickBtnNum = 0;
    var isLnkNmModify = 1;

    $(function () {
        initTab();
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/project/prjlnkcomp/initList.do',
            method: 'get',
            columns: [

				{ display: '<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="合同到期提醒"></span>',
					name: '', minWidth: 30, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) {
						var h = '';
						if(rowdata.isValid == "2"){//合同到期提醒
							h = '<i class="ico_flasher"></i>';
						}else if(rowdata.isValid == "1"){
							h = '<i class="ico_flasher_blue"></i>';
						}
						return h;
					}
                },
                { display: '挂靠公司ID', name: 'id', minWidth: 120, align:'center', enabledSort:true,hide:true
                },
                {
                    display: '挂靠公司名称', name: 'lnkCompNm', minWidth: 250,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        h = '<a  href="javascript:detailBtn(';
                        h += "'" + rowdata.id + "'";
                        h += ')">' + value + '</a>'
                        return h;
                    }
                },
                { display: '挂靠公司星级', name: 'starLevelNm',width: 100},
                { display: '挂靠公司归属代码', name: 'ownerCd',width: 60,hide:true
                },
                { display: '挂靠公司归属', name: 'ownerCdNm',width: 100
                },
                {display: '道路运输许可证有效期', name: 'expDt', render: renderDate, minWidth: 140},
                {display: '成立日期', name: 'regDt', minWidth: 140, render: renderDate, enabledSort: true},
                {display: '企业类型', name: 'compTyp', minWidth: 100},
                {display: '法人代表', name: 'corpRep', minWidth: 100},
                {display: '联系人', name: 'lnkNm', minWidth: 100},
                {display: '在我司累积挂靠车辆', name: 'ourTotLnkQyt', minWidth: 140},
                {
                    display: '所属机构', name: 'buOrgCdNms', align: 'left', width: 200, isEllipsis: false,
                    render: function (rowdata, rowindex, value) {
                        if (StringUtils.isEmpty(value)) {
                            return "";
                        } else {
                            var h = '<span class="gridTip" title="' + value + '">' + value + '</span>'
                            return h;
                        }
                    }
                },
                {
                    display: '审核状态', minWidth: 140, render: function (rowdata, rowindex, value) {
                        return rowdata.audStsCdNm;
                    }
                },
                {
                    display: '是否黑名单', minWidth: 140, render: function (rowdata, rowindex, value) {
                        if (rowdata && rowdata.isBlackList==1) {
                            return "是";
                        } else {
                            return "否";
                        }
                    }
                },
                {
                    display: '流程编号', minWidth: 220, isEllipsis: false, render: function (rowdata, rowindex, value) {
                    if (rowdata && rowdata.sysFlowSHDTOList && rowdata.sysFlowSHDTOList.length == 1) {
                        var pno = rowdata.sysFlowSHDTOList[0].pno;
                        var audStsCd = rowdata.sysFlowSHDTOList[0].audStsCd;
                        var pinstId = rowdata.sysFlowSHDTOList[0].pinstId;
                        var dataId = rowdata.sysFlowSHDTOList[0].dataId;
                        if (StringUtils.isNotEmpty(pinstId)
                            && StringUtils.isNotEmpty(audStsCd)
                            && StringUtils.isNotEmpty(dataId)
                            && StringUtils.isNotEmpty(pno)) {
                            var h = '<a href="javascript:showFlow(';
                            h += "'" + pinstId + "'";
                            h += ",'" + audStsCd + "'";
                            h += ",'" + dataId + "'";
                            h += ')">' + pno + '</a>';
                            return h;
                        }
                    } else if (rowdata && rowdata.sysFlowSHDTOList && rowdata.sysFlowSHDTOList.length > 1) {
                        var h = "";
                        for (var i = 0; i < rowdata.sysFlowSHDTOList.length; i++) {
                            if (i != 0) {
                                h += '</br>';
                            }
                            var pno = rowdata.sysFlowSHDTOList[i].pno;
                            var audStsCd = rowdata.sysFlowSHDTOList[i].audStsCd;
                            var audStsCdNm = rowdata.sysFlowSHDTOList[i].audStsCdNm;
                            var pinstId = rowdata.sysFlowSHDTOList[i].pinstId;
                            var dataId = rowdata.sysFlowSHDTOList[i].dataId;
                            h += '<a href="javascript:showFlow(';
                            h += "'" + pinstId + "'";
                            h += ",'" + audStsCd + "'";
                            h += ",'" + dataId + "'";
                            h += ')">' + pno + '</a>';
                            h += "-";
                            h += audStsCdNm;
                        }
                        return h;
                    }
                }
                },
                getOptColumn()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            //isScroll: false,
            fixedCellHeight: false,
            checkbox: true,
            rownumbers: true
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(500);
        $("#searchBar").ligerForm();
        $('#reasonFromSet').ligerForm({
	        validate : true
		});

        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            data["lnkCompNm"] = $("#lnkCompNm").val();
            data["audStsCd"] = $("#audStsCd").val();
            data["rlNm"] = $("#rlNm").val();
            data["certNo"] = $("#certNo").val();
            data["rlTel"] = $("#rlTel").val();
            /*   data["orgCd"] = $("#orgCd").val(); */
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            ;
            grid.reload();
        });

        $("#pageloading").hide();

        $('#lnkCompNmBk').bind('input', function(){
        	if(clickBtnNum < 2){
        		$('#hintSpan').css('display', 'none');
        		$('#okBtn1').css('display', 'inline-block');
        		$('#okBtn2').css('display', 'none');
        	}
        });

    });

    var ligerForm;

    function addBefore() {
        addDialog = $.ligerDialog.SQopen({
            width: 800,
            top: 100,
            title: '新增',
            target: $("#div_lnk_comp")
        });
        ligerForm = $("#div_lnk_comp_form").ligerForm({
            validate: true
        });

        //清空字段值
        resetForm(ligerForm);
    }

    $('#cancelBtn').click(function(){
    	$.ligerDialog.hide();
    });
    $('#okBtn1').click(function(){//确定
    	isLnkNmModify = 0;
    	checkIsOk();
    });
    $('#okBtn2').click(function(){//继续编辑
    	isLnkNmModify = 1;
    	checkIsOk();
    });

    function resetForm(ligerForm) {
        ligerForm.setData({
            lnkCompNmBk: "",
            orgCode: "",
            bizLicNo: "",
            taxRegNo: ""
        });
    }

    //检查是否存在公司信息
    function checkIsOk() {
        if (!ligerForm.valid()) {
            UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
            return false; //验证不通过，不执行以下代码
        }

        var data = ligerForm.getData();
        data["lnkCompNm"] = data.lnkCompNmBk;
        data["orgCode"] = data.orgCode;
        data["bizLicNo"] = data.bizLicNo;
        data["taxRegNo"] = data.taxRegNo;
        data["clickBtnNum"] = clickBtnNum;

        var _url = '<%=path%>/project/prjlnkcomp/getExistComp.do';
        AjaxUtils.ajaxGet(_url, data, function (msg) {
			if(msg.success == 1){

				if(msg.info == 0){
					 sign = 1;
					 if(clickBtnNum < 2 && isLnkNmModify == 0){
						 clickBtnNum++;
						//top.$.ligerDialog.SQalert({content:"系统未在工商网中查到此公司，继续操作请点击确定", SQ_type: "success"});
						$('#hintSpan').css('display', 'block');
						$('#okBtn1').css('display', 'none');
						$('#okBtn2').css('display', 'inline-block');
						return ;
					 }
				}

				var callback = function () {
				    grid.reload();
                }

				var _id = msg.id;
				if(_id){
					top.$.ligerDialog.confirm("挂靠公司已存在,是否跳转修改页面", function (flag) {
			   			if(flag == false){
			   				$.ligerDialog.hide();//关闭窗口
			   				return;
			   			}
			   			//parent.mainApp.f_addTab('tab_prj_lnk_comp_add' + _id, '修改挂靠公司', '<%=path%>/project/prjlnkcomp/toModifyPage.do?id=' + _id);
			   			Add_navTab('tab_prj_lnk_comp_add' + _id, '修改挂靠公司', '<%=path%>/project/prjlnkcomp/toModifyPage.do?id=' + _id+'&isShowRate=0', callback);

			   			$.ligerDialog.hide();//关闭窗口
			   		});
				}else{
					var param;
                    var postParam = {};
	                var timestamp = (new Date()).valueOf();
                    postParam.lnkCompNm = data.lnkCompNm;
                    //2020-06-10 12:40:52 三方数据关停
                    /*if(msg.info == 1){
                        postParam.hsjBasicId = msg.data;
                        /!*postParam.creditcode = msg.data.creditCode;
                        postParam.entType = msg.data.entType;
                        postParam.address = msg.data.address;
                        postParam.opendate = msg.data.openFrom;
                        postParam.busiscope = msg.data.operateScope;*!/
                        postParam.importDataSource = "HAOSHUJU";
						// param = "?lnkCompNm=" + data.lnkCompNmBk + "&creditcode=" + msg.data.creditCode + "&entType=" + msg.data.entType
                    	// + "&address=" + msg.data.address + "&opendate=" + msg.data.openFrom + "&busiscope=" + msg.data.operateScope +"&importDataSource=HAOSHUJU&hsjBasicId="+msg.data.id;
                        param = "?lnkCompNm=" + data.lnkCompNmBk +"&importDataSource=HAOSHUJU&hsjBasicId="+msg.data;
					}else{*/
                        postParam.importDataSource = "INNER";
						param = "?lnkCompNm=" + data.lnkCompNmBk + "&importDataSource=INNER" ;
					//}
					param += "&isLnkNmModify=" + isLnkNmModify;
					param +="&isShowRate=0";
                    postParam.isLnkNmModify = isLnkNmModify;
                    //parent.mainApp.f_addTab('tab_prj_lnk_comp_add' + timestamp, '新增挂靠公司', '<%=path%>/project/prjlnkcomp/toModifyPage.do' + param);
                    Add_navTab('tab_prj_lnk_comp_add' + timestamp, '新增挂靠公司', '<%=path%>/project/prjlnkcomp/toModifyPage.do' + param, callback);
                    //Add_navTab_post(postParam, '<%=path%>/project/prjlnkcomp/toModifyPage.do', '新增挂靠公司', callback);
                    //Add_navTab_post('tab_prj_lnk_comp_add' + timestamp, '新增挂靠公司', '<%=path%>/project/prjlnkcomp/toModifyPage.do', callback, postParam);
                    $.ligerDialog.hide();//关闭窗口
				}
			 }else if(msg.success == 0){
				 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 //frameElement.dialog.close();
			 }
        }, true);
    };

    /**
     * @iframe_id iframe的id
     * @action post 地址
     * @title tab标签的显示名称
     * @params: Object
     *  - @postData 键值对json对象
     *  - @callback 回调方法
     */
    function Add_navTab_post(iframe_id, title, action, receive, postData) {
        var _form = $('<form id="myForm" method="post" target="'+iframe_id+'" action="'+action+'" style="height: 0; overflow: hidden;"></form>')
        var _keys = Object.keys(postData)
        _keys.forEach(function (key) {
            _form.append('<input type="hidden" name="'+key+'" value="'+postData[key]+'" />')
        })
        top.$('body').append(_form)
        Add_navTab(iframe_id, title, '/', receive);
        _form.submit()
        _form.remove()
    }

    //显示流程
    function showFlow(_pInstId, _audStsCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/prjlnkcomp/toDetailPage.do?id=" + _businessKey + "@@processInstanceId=" + _pInstId + "@@projectId=";
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_prj_lnk_comp_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

    //获取操作列
    function getOptColumn() {
        var column = {
            display: '操作',
            isSort: false,
            width: 350,
            align: 'left',
            render: function (rowdata, rowindex, value) {
                var h = "";
                //if(rowdata.audStsCd==CommonConstant.C_AUD_NO_HAPPEN_CODE){
                h += '<a class="sq-button-hasicon" href="javascript:modifyBtn(';
                h += "'" + rowdata.id + "'";
                h += ",'" + rowdata.audStsCd + "'";
                h += ')"><i class="sqBtnIco_4"></i>修改</a>'
                h += '<a class="sq-button-hasicon" href="javascript:removeBtn(';
                h += "'" + rowdata.id + "'";
                h += ')"><i class="sqBtnIco_7"></i>删除</a>'
                //	 }
                var m = "";
                m += '<a class="sq-button-hasicon" href="javascript:modifyZKBtn(';
                m += "'" + rowdata.id + "',";
                m += "'" + rowdata.audStsCd + "'";
                m += ')"><i class="sqBtnIco_4"></i>变更</a>'
                var cr = "";
                cr += '<a class="sq-button-hasicon" href="javascript:linkCrAmtBtn(';
                cr += "'" + rowdata.id + "'";
                cr += ')"><i class="sqBtnIco_4"></i>敞口</a>'
                var isShowCmtBtn = $("#isShowCmtBtn");
                var isShowAudBtn = $("#isShowAudBtn");
                var isShowLinkCrAmtBtn = $("#isShowLinkCrAmtBtn");
                var isShowLnkModifyBtn = $("#isShowLnkModifyBtn");
                var blackList = $("#blackList");
                var end = "";
                var w = "";
                //有修改删除权限 && 审核状态:待提交||审核不通过  -->修改删除显示
                if (isShowCmtBtn.length) {
                    if (rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_NON || rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_NO_PASS || rowdata.audStsCd == '' || rowdata.audStsCd == null) {
                        end += h;
                    }
                }
                if (isShowLnkModifyBtn.length) {
                    if (rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_PASS) {
                        w += m;
                    }
                    /*if (rowdata.audStsCd != '99' && rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_NON
                    		&& rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_NO_PASS) { //99 变更审核中
                        end += m;
                    }*/
                }

                //if (buOrgCd == ProjectConstant.CODE_BU_ORG_CD_CAR) {
                w += '<a class="sq-button-hasicon" href="javascript:toCompBankList(';
                w += "'" + rowdata.id + "'";
                w += ')"><i class="sqBtnIco_1"></i>挂靠公司账号</a>';
                //}
                w += cr;
                var isLnkRiskLog = $("#isLnkRiskLog");
                if (isLnkRiskLog.length) {
                    var opLogBtn = '<a class="sq-button-hasicon" href="javascript:searchOpLog(';
                    opLogBtn += "'"+rowdata.id+"'";
                    opLogBtn += "," + "'" + rowdata.lnkCompNm + "'";
                    opLogBtn += ')"><i class="sqBtnIco_4"></i>操作日志</a>';
                    w += opLogBtn;
                }


                return end + SQ.dropLinks(w);
            }
        }
        return column;
    }

 	// 操作日志
 	function searchOpLog(_id,_lnkCompNm){
        var url = '';
        url = '<%=path%>/risk/rskCstSignLog/toDetailListPage.do?cstId=' + _id + '&cstNm=' + _lnkCompNm + '&signSource=LNK&cstTypeCd=3&cstIdcard=';
        var title = '操作日志';
        $.ligerDialog.open({
            width: 1000,
            height: 500,
            title: title,
            url: url
        });
 	}

    function clearBtn() {
        var form = new liger.get("searchBar");
        form.setData({
            lnkCompNm: " ",
            audStsCd: " ",
            rlNm: " ",
            rlTel: " ",
            certNo: " ",
        });
    }

    function modifyAudStsCd(id, audStsCd) {
        var data = {};
        data.id = id;
        data.audStsCd = audStsCd;
        var url = '<%=path%>/project/prjlnkcomp/modifyAudStsCd.do';
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    grid.reload();
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function changeAudStsCd(id) {
        $.ligerDialog.SQopen({
            width: 500,
            height: 200,
            title: '审核信息',
            url: '<%=path%>/project/prjlnkcomp/toModifyAudStsCdPage.do?id=' + id,
            buttons: [{
                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    if (Dialog.onOk) Dialog.onOk();
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ]
        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    function toCompBankList(_id) {
        if (!_id) return;
        Add_navTab('PrjComp_4' + _id, '挂靠公司账号', "<%=path%>/project/prjLnkCompBkAcc/toListPage.do?compId=" + _id);
    }

    //挂靠公司详情
    function detailBtn(id) {
        parent.mainApp.f_addTab('tab_prj_lnk_comp_detail' + id, '挂靠公司详情', '<%=path%>/project/prjlnkcomp/toDetailPage.do?id=' + id+'&isMask=1');
    }

    //添加挂靠公司
    function addBtn() {
        var callback = function () {
            grid.reload();
        }
        var timestamp = new Date().getTime();
        Add_navTab('tab_prj_lnk_comp_add' + timestamp, '添加挂靠公司', '<%=path%>/project/prjlnkcomp/toAddPage.do', callback);
    }

    //修改挂靠公司详情
    function modifyBtn(id, audStsCd) {
        var callback = function () {
            grid.reload();
        }
        Add_navTab('tab_prj_lnk_comp_add' + id, '修改公司详情', '<%=path%>/project/prjlnkcomp/toModifyPage.do?id=' + id + "&audStsCd=" + audStsCd+"&isShowRate=0", callback);
    }

    function linkCrAmtBtn(id) {
    	 var callback = function () {
             grid.reload();
         }
         Add_navTab('tab_prj_lnk_comp_LinkCrAmt' + id, '敞口', '<%=path%>/project/prjlnkcomp/toModifyPage.do?LinkCrAmt=1&id=' + id, callback);
    }

    function modifyZKBtn(id, audStsCd) {
        var callback = function () {
            grid.reload();
        }
        Add_navTab('tab_prj_lnk_comp_add' + id, '修改公司详情', '<%=path%>/project/prjLnkCompApply/toModifyPage.do?id=' + id + '&&audStsCd=' + audStsCd +'&isShowRate=0', callback);
    }


    //删除所选挂靠公司
    function removeBtn() {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length < 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
            return;
        }
        var _ids = [];
        for (var index in selectedRows) {
            _ids.push(selectedRows[index].id);
        }
        $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
            if (flag == false) return;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {ids: JSON.stringify(_ids)},
                url: '<%=path%>/project/prjlnkcomp/removeByIds.do',
                success: function (msg) {
                    if (msg.success == 1) {
                        grid.reload();
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    function flowStartBtn() {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        var isBlackList = selectedRows[0].isBlackList;
        if (isBlackList == "1" || isBlackList == "4") {
            $.ligerDialog.SQalert({content: "标记为黑名单不允许发起流程.", SQ_type: "warning"});
            return;
        }
        var audStsCd = selectedRows[0].audStsCd;
        if (audStsCd == "1" || audStsCd == "4") {
            $.ligerDialog.SQalert({content: "审核中,不允许多次发起流程.", SQ_type: "warning"});
            return;
        } else if (audStsCd == "2") {
            $.ligerDialog.SQalert({content: "审核通过,不允许再次发起流程.", SQ_type: "warning"});
            return;
        }
        var url = null;
        var prjLnkCompId = selectedRows[0].id;
        if (buOrgCd != ProjectConstant.CODE_BU_ORG_CD_CAR ) {
            url = '<%=path%>/project/prjlnkcomp/addZkFlowStart.do?prjLnkCompId=' + prjLnkCompId;
        } else {
            url = '<%=path%>/project/prjlnkcomp/addFlowStart.do?prjLnkCompId=' + prjLnkCompId;
        }

        $.ligerDialog.confirm(FlowConstant.FLOW_ADD_START_CONFIRM, function (flag) {
            if (flag == false) return;
            var wait_dialog = $.ligerDialog.SQalert({
                content: LogUtils.LOG_CMM_DATA_LOADING,
                SQ_type: "waitting",
                onClose: function () {
                }
            });
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: url,
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {//成功发起流程
                        var url = '<%=path%>/flow/flow/getFlowNextAssigne.do?key=' + msg.info;
                        FlowUtils.alertNextFlowAssign(url);
                        $.ligerDialog.SQalert({content: "流程发起成功", SQ_type: "success"});
                        grid.reload();
                    } else if (msg.success == 0) {//错误
                        UIUtils.alertErrorHold1(msg.info);
                    }

                }
            });
        });

    }

    var loadedTabs = [];

    //初始化Tab页签
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onBeforeSelectTabItem: function (tabid) {
                var selectedRows = grid.getSelectedRows();
                if (tabid != "tabA") {
                    if (selectedRows.length != 1) {
                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                        return false;
                    }
                }
            },
            onAfterSelectTabItem: function (tabid) {
                var selectedRows = grid.getSelectedRows();
                if (tabid != "tabA") {
                    if (selectedRows.length != 1) {
                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                        return false;
                    } else {
                        if (loadedTabs.indexOf(selectedRows[0].id) < 0) {
                            loadedTabs = [];
                            loadedTabs.push(selectedRows[0].id);
                            switch (tabid) {
                                case "tabB":
                                    pageInTab.setTabItemSrc(tabid, "<%=path%>/project/prjlnkcomp/toPrjLinkFlowPage.do?linkId=" + selectedRows[0].id);
                                    break;
                                <%-- case "tabC":
                                    pageInTab.setTabItemSrc(tabid, "<%=path%>/project/prjLnkCompApply/prjCompApplyProcessPage.do?linkId=" + selectedRows[0].id);
                                    break;  --%>
                            }
                        }
                        SetIframe_height();
                    }
                }
            }
        });
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    };
</script>

</body>
</html>
